#include "stdafx.h"
#include "LoginConnGS.h"
#include "Utils/Debug.h"
#include "GSGlobal.h"

void LoginConnGS::onAccept(EssAcceptor* acceptor, EssConnector* connector)
{
	char* ip;
	u_short port;
	if( connector->getPeerName(&ip, &port) )
	{
		char log[MAX_PATH] = {0};
		sprintf_s(log, "Accept a new LoginSrv IP=%s, Port=%d.\n", ip, port);
		mLog += log;
	}
}

bool LoginConnGS::onReceive(EssConnector* connector)
{
	char* ip;
	u_short port;
	if ( connector->getPeerName(&ip, &port) )
	{
		char log[MAX_PATH] = {0};
		sprintf_s(log, "Recv Msg From LoginSrv IP=%s, Port=%d.\n", ip, port);
		mLog += log;
		//Log->log(std::string(log));
	}
	
	char* res = (char*)connector->getRecvBuffer().base();
	Log->log(std::string(res));
	
	return true;
}

void LoginConnGS::onDisconnect(EssConnector* connector)
{
	char* ip;
	u_short port;
	if ( connector->getPeerName(&ip, &port) )
	{
		char log[MAX_PATH] = {0};
		sprintf_s(log, "A LoginSrv disconnect IP=%s, Port=%d.\n", ip, port);
		mLog += log;
	}
	removeConnector(connector);
}

void LoginConnGS::broadcast(const char* buf, int len)
{
	for ( ConnectorIterator c = mConnectors.begin(); c != mConnectors.end(); ++c )
	{
		c->second->sendSock(buf, len);
	}
}